﻿/*==============================================================
 * ArticleExtensions.cs
 * Copyright (C) 2014 贵州惠众互联 Inc. All rights reserved.
 *==============================================================
 * Author:   罗应红
 * Date:     2014/03/06 15:54:35.
 * Version:  1.0
 * QQ:		 88962800
*==============================================================*/

using System;
using System.Collections.Generic;
using System.Linq;
using QDT.Common;
using QDT.Core.Domain;
using QDT.Web.Models;

namespace QDT.Web.Helper {
    public static class ArticleExtensions {
        public static IPagedList<ArticleModel> ToModelList(this IPagedList<Article> articles) {
            var data = articles.Select(ToModel);
            return new StaticPagedList<ArticleModel>(data,articles.PageIndex,articles.PageSize,articles.TotalItemCount);
        }

        public static ArticleModel ToModel(this Article article) {
            return new ArticleModel {
                IsEffect = article.IsEffect,
                Id = article.ID,
                Title = article.Title,
                Sort = article.Sort,
                Content = article.Content,
                IsDelete = article.IsDelete,
                Brief = article.Brief,
                CreateTime = article.CreateTime,
                AddAdminId = article.AddAdminId,
                ClickCount = article.ClickCount,
                RelUrl = article.RelUrl,
                SeoDescription = article.SeoDescription,
                SeoKeyWord = article.SeoKeyWord,
                SeoTitle = article.SeoTitle,
                SubTitle = article.SubTitle,
                UName = article.UName,
                UpdateAdminId = article.UpdateAdminId,
                CateId = article.CateId,
                CateName = article.Cate.Title,
                UpdateTime = article.UpdateTime,
                Photo=article.Photo
            };
        }

        public static IList<NoticeModel> ToNoticeModelList(this IList<Article> articles ) {
             return articles.Select(ToNoticeModel).ToList();
         }
        public static NoticeModel ToNoticeModel(this Article article) {
            return new NoticeModel {
                Id = article.ID,
                Title = article.Title,
                CreateTime =  article.CreateTime,
                CateId = article.CateId
            };
        }
    }
}